package com.jmga.ecogasfinder.activities.maps.overlays;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class GasStationsOverlay extends ItemizedOverlay<OverlayItem> {

	private Context mContext;
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	
	public GasStationsOverlay(Drawable defaultMarker, Context context) {
		  super(boundCenterBottom(defaultMarker));
		  this.mContext = context;
		}

	public void addOverlay(OverlayItem overlay, Drawable drawable) {
		if(drawable != null) {
			overlay.setMarker(boundCenterBottom(drawable));
		}
		this.mOverlays.add(overlay);
	    populate();
	}
	
	@Override
	protected OverlayItem createItem(int i) {
	  return this.mOverlays.get(i);
	}
	
	@Override
	public int size() {
	  return this.mOverlays.size();
	}
	
	@Override
	protected boolean onTap(int index) {
	  if(this.mContext != null && this.mOverlays.size() > index) {
		  OverlayItem item = this.mOverlays.get(index);
		  AlertDialog.Builder dialog = new AlertDialog.Builder(this.mContext);
		  dialog.setTitle(item.getTitle());
		  dialog.setMessage(item.getSnippet());
		  dialog.show();
	  }
	  return true;
	}
}
